package com.ychs.dpmms.service;

import com.ychs.dpmms.dao.RoleMapper;
import com.ychs.dpmms.entity.Role;
import com.ychs.dpmms.util.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * copyright(c)2021 YYB.ALL rights Reserved
 * <p>
 * 描述:
 *
 * @author 原玉波
 * @version 1.0
 * @date 2021/5/30
 */
@Service
public class RoleService implements IBaseService<Role> {

    //slf4j日志对象
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private RoleMapper mapper;

    /**
     * 添加记录
     *
     * @param role 记录对象
     * @return 是否成功
     */
    @Override
    public boolean add(Role role) {
        boolean result = false;
        result = mapper.insert(role) == Constants.UPDATE_SUCCESS;
        if (result) {
            //如果增加角色成功，再增加对应的权限关系
            mapper.insertRel(role);
        }
        return result;
    }

    /**
     * 修改记录
     *
     * @param role 修改记录对象
     * @return 成功与否
     */
    @Override
    public boolean modify(Role role) {
        boolean result = false;
        result = mapper.update(role) == Constants.UPDATE_SUCCESS;
        return result;
    }

    /**
     * 删除记录
     *
     * @param id 待删除记录的主键
     * @return 是否成功
     */
    @Override
    public boolean remove(int id) {

        boolean result = false;
        result = mapper.delete(id) == Constants.UPDATE_SUCCESS;
        return result;
    }

    /**
     * 查询单个对象
     *
     * @param id 查询对象的主键
     * @return 查询结果
     */
    @Override
    public Role searchById(int id) {
        Role role = new Role();
        role = mapper.selectById(id);
        return role;
    }

    /**
     * 查询多条记录
     *
     * @param conditions 查询条件
     * @return 查询结果
     */
    @Override
    public List<Role> search(Map<String, Object> conditions) {
        List<Role> roles = mapper.select(conditions);
        return roles;
    }

    /**
     * 按照条件查询记录总数
     *
     * @param conditions 条件
     * @return 符合条件的记录总数
     */
    @Override
    public int searchTotalNumber(Map<String, Object> conditions) {
        return 0;
    }

}
